import http from '../utils/http'

export const positionsAdd = () => {
  return new Promise((resolve, reject) => {
    const options = {
      url: '/api/positions/add',
      type: 'post',
      // beforeSubmit: beforeCheck, // 提交前的回调函数
      success: (res) => {
        resolve(res)
      },
      error: (err) => {
        reject(err)
      },
      dataType: 'json',
      // clearForm: true,
      resetForm: true,
      timeout: 3000
    }
    $('#positions-form').ajaxSubmit(options)
  })
}

export const positionsList = async () => {
  try {
    let { res } = await http({
      url: '/api/positions'
    })
    return res
  } catch(err) {
    console.log(err)
  }
}

export const positionsListone = async (id) => {
  try {
    let { res } = await http({
      url: '/api/positions/listone',
      data: {
        id
      }
    })
    return res
  } catch(err) {
    console.log(err)
  }
}

export const positionsUpdata = () => {
  return new Promise((resolve, reject) => {
    const options = {
      url: '/api/positions',
      type: 'patch',
      // beforeSubmit: beforeCheck, // 提交前的回调函数
      success: (res) => {
        resolve(res)
      },
      error: (err) => {
        reject(err)
      },
      dataType: 'json',
      // clearForm: true,
      resetForm: true,
      timeout: 3000
    }
    $('#positions-form-updata').ajaxSubmit(options)
  })
}
